/**
 * 
 */
package co.gov.medellin.sdep.sisdep.cco.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.cco.exception.LocalCentroComercialException;
import co.gov.medellin.sdep.sisdep.cco.exception.LocalCentroComercialRuntimeException;
import co.gov.medellin.sdep.sisdep.cco.exception.descriptor.LocalCentroComercialMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.LocalCentroComercial;
import co.gov.medellin.sdep.sisdep.model.dao.impl.ILocalCentroComercialDAOT;

/**
 * @author Usuario
 *
 */
public class LocalCentroComercialServiceImpl extends BaseService implements ILocalCentroComercialService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private ILocalCentroComercialDAOT localCentroComercialDAO;

	/**
	 * 
	 */
	public LocalCentroComercialServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(LocalCentroComercial localCentroComercial) throws LocalCentroComercialException {
		try{
			localCentroComercial.setUsuarioCrea(getPrincipalUser());
			localCentroComercial.setFechaCrea(new Date());
			getLocalCentroComercialDAO().insert(localCentroComercial);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new LocalCentroComercialException(new LocalCentroComercialMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new LocalCentroComercialException(new LocalCentroComercialMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(LocalCentroComercial localCentroComercial) throws LocalCentroComercialException {
		try{
			localCentroComercial.setUsuarioModifica(getPrincipalUser());
			localCentroComercial.setFechaModifica(new Date());
			getLocalCentroComercialDAO().update(localCentroComercial);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new LocalCentroComercialRuntimeException(new LocalCentroComercialMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new LocalCentroComercialRuntimeException(new LocalCentroComercialMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(LocalCentroComercial localCentroComercial) throws LocalCentroComercialException {
		try {
			localCentroComercial.setUsuarioModifica(getPrincipalUser());
			localCentroComercial.setFechaModifica(new Date());
			getLocalCentroComercialDAO().delete(localCentroComercial);
		}catch (Exception e) {
			Object [] infoError = {
			};
			throw new LocalCentroComercialRuntimeException(new LocalCentroComercialMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, LocalCentroComercial localCentroComercial) throws LocalCentroComercialException {
		try{
			//return getLocalCentroComercialDAO().getAllLocalCentroComercialPaginated(start, max, criteria);
			return getLocalCentroComercialDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new LocalCentroComercialRuntimeException(new LocalCentroComercialMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	/**
	 * @return 
	 * 
	 */
	public final List loadByIdCCo(int start,int max, LocalCentroComercial localCentroComercial) throws LocalCentroComercialException {
		try{
			//return getLocalCentroComercialDAO().getAllLocalCentroComercialPaginated(start, max, criteria);
			return getLocalCentroComercialDAO().loadByIdCCo(localCentroComercial);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new LocalCentroComercialRuntimeException(new LocalCentroComercialMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	/**
	 * 
	 */
	public final LocalCentroComercial get(long id) throws LocalCentroComercialException {
		try{
			return getLocalCentroComercialDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new LocalCentroComercialRuntimeException(new LocalCentroComercialMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public ILocalCentroComercialDAOT getLocalCentroComercialDAO() {
		return localCentroComercialDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setLocalCentroComercialDAO(ILocalCentroComercialDAOT localCentroComercialDAO) {
		this.localCentroComercialDAO = localCentroComercialDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
